<?php
declare (strict_types=1);

namespace app\admin\controller;

use think\Request;
use app\admin\validate\MarketSocialMediaAccountGroup as MarketSocialMediaAccountGroupValidate;
use app\admin\service\SystemSMChannel as SystemSMChannelService;
use app\admin\service\MarketSocialMediaAccountGroup as MarketSocialMediaAccountGroupService;

class MarketSocialMediaAccountGroup
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index(Request $request, MarketSocialMediaAccountGroupService $service, MarketSocialMediaAccountGroupValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('search')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }

        $param['name'] = $request->param('name', null);
        $param['channel_id'] = $request->param('channel_id', null);

        $intPage = $request->param('pageIndex', 1);
        $intPageSize = $request->param('pageSize', 50);
        $arrData = $service->index($param, (int)$intPage, (int)$intPageSize);
        return json($arrData);
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        //
    }

    /**
     * 保存新建的资源
     *
     * @param \think\Request $request
     * @return \think\Response
     */
    public function save(Request $request, MarketSocialMediaAccountGroupService $service, MarketSocialMediaAccountGroupValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('save')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['operator_id'] = $request->operator_id;
        $param['channel_id'] = $request->param('channel_id', '');
        $param['name'] = $request->param('name', '');
        $param['remark'] = $request->param('remark', '');
        $param['status'] = $request->param('status', '');

        $arrData = $service->save($param);
        return json($arrData);
    }

    /**
     * 显示指定的资源
     *
     * @param int $id
     * @return \think\Response
     */
    public function read($id)
    {
        //
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param int $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param \think\Request $request
     * @param int $id
     * @return \think\Response
     */
    public function update(Request $request, MarketSocialMediaAccountGroupService $service, MarketSocialMediaAccountGroupValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('update')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['id'] = $request->param('id', null);
        $param['operator_id'] = $request->operator_id;
        $param['channel_id'] = $request->param('channel_id', '');
        $param['name'] = $request->param('name', '');
        $param['remark'] = $request->param('remark', '');
        $param['status'] = $request->param('status', '');

        $arrData = $service->update($param);
        return json($arrData);
    }

    /**
     * 删除指定资源
     *
     * @param int $id
     * @return \think\Response
     */
    public function delete(Request $request, MarketSocialMediaAccountGroupService $service, MarketSocialMediaAccountGroupValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('delete')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['operator_id'] = $request->operator_id;
        $param['ids'] = $request->param('ids', null);

        $arrData = $service->delete($param);
        return json($arrData);
    }

    /**
     * 修改状态
     * @param Request $request
     * @param MarketSocialMediaAccountGroupService $service
     * @param MarketSocialMediaAccountGroupValidate $validate
     * @return \think\response\Json
     * 2024-10-28 19:17:42
     * author: jiang
     */
    public function status(Request $request, MarketSocialMediaAccountGroupService $service, MarketSocialMediaAccountGroupValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('status')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['operator_id'] = $request->operator_id;
        $param['ids'] = $request->param('ids', []);
        $param['status'] = $request->param('status', null);

        $arrData = $service->status($param);
        return json($arrData);
    }

    /**
     * 资源列表
     * @param Request $request
     * @param SystemSMChannelService $service
     * @param MarketSocialMediaAccountGroupValidate $validate
     * @return \think\response\Json
     * 2024-10-28 19:21:59
     * author: jiang
     */
    public function resource(SystemSMChannelService $service)
    {
        $arrData = $service->getSelectData();
        return json($arrData);
    }
}
